home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Chassis 6.0 ƒ / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  10.4 KB  |  297 lines  |  [TEXT/KAHL]

  1. /************************************************************************************/
  2. /*                                                                                    */
  3. /*    Program Name:  Chassis                                                            */
  4. /*  Version:  6.0                                                                    */
  5. /*                                                                                    */
  6. /*    by:        Charles A. Hoffman                                                        */
  7. /*                                                                                    */
  8. /*            ASSIST Consulting            - or -            GTE Laboratories            */
  9. /*            147 Vernon Street                            Mail Stop 24                */
  10. /*            Norwood, MA  02062                            40 Sylvan Road                */
  11. /*                                                        Waltham, MA  02254            */
  12. /*                                                                                    */
  13. /*            Phone: (617) 551-0185                        Phone: (617) 466-2131        */
  14. /*                                                                                    */
  15. /*            America Online: chuck01                        Internet:  chuck@gte.com    */
  16. /*            ( AOL Internet: chuck01@aol.com )                                        */
  17. /*                                                                                    */
  18. /************************************************************************************/
  19. /*                                                                                    */
  20. /*    Copyright 1992 Charles A. Hoffman.                                                */
  21. /*                                                                                    */
  22. /************************************************************************************/
  23. /*                                                                                    */
  24. /*    You may incorporate this source code into your own non-commercial product, as    */
  25. /*    long as the notice, below, is included, and you declare and register your own    */
  26. /*    copyright.  Permission to include this code in a commercial product is not        */
  27. /*    granted, and must be obtained in writing from the copyright owner, listed        */
  28. /*    above.  If you change this source code, you may not continue to use the         */
  29. /*    copyrighted name "Chassis" but may use a different name on your application.    */
  30. /*    The notice, below, must still be included.                                        */
  31. /*                                                                                    */
  32. /************************************************************************************/
  33. /*                                                                                    */
  34. /*        This program contains material from a version of the sample program            */
  35. /*        "Chassis," and the application program "MacEden," which were originally        */
  36. /*        created and copyrighted by Charles A. Hoffman.                                */
  37. /*                                                                                    */
  38. /************************************************************************************/
  39. /*                                                                                    */
  40. /*    Compiled with Symantec Corp. THINK C 6.0 for Macintosh                            */
  41. /*                                                                                    */
  42. /************************************************************************************/
  43. /*                                                                                    */
  44. /*    6.0.0 - Made compatable with THINK C 6.0, and downward compatable with 5.0.4.    */
  45. /*    5.1.2 - Fix to enable running in 32-bit mode on Mac-IIci and above (credit to    */
  46. /*            Jim Ulrey, Paul Bennell, and Marcelino Bernardo is in myActionProc.c).    */
  47. /*            Fix for two small memory leaks.  Change author's address.                */
  48. /*    4.3.1 -    Small fix to enable running on Mac Plus.  Major changes to                */
  49. /*            print routines.    Small fixes for cursor behavior.  Changes to scrolling    */
  50. /*            in Help routines.                                                        */
  51. /*    4.2.2 -    Minor bug fix for scrolling in myActionProc and HelpGetProc.            */
  52. /*    4.2.1 -    First public release.                                                    */
  53. /*                                                                                    */
  54. /************************************************************************************/
  55.  
  56. #include "MyHeaders.h"
  57.  
  58. /************************************************************************************/
  59. /*    MAIN                                                                            */
  60. /************************************************************************************/
  61. main()
  62. {
  63.     MainRetCode = 0;                                /* initialize return code        */
  64.     
  65.     myResRefNum = CurResFile();                        /* Get own resource file number    */
  66.  
  67.     versRecHandle = (struct versRec **) GetResource ('vers',1);    /* get vers resrce    */
  68.     HLock ((Handle) versRecHandle);
  69.     j = (short) (**versRecHandle).versChar[6];
  70.     k = (short) (**versRecHandle).versChar[6+1+j];    /* k is length of long string    */
  71.     for (m = 0; m < k+2; m++)
  72.         versLongStr[m] = (**versRecHandle).versChar[6+j+1+m];
  73.     HUnlock ((Handle) versRecHandle);
  74.     ReleaseResource ((Handle) versRecHandle);
  75.     
  76.     WorkRetCode = InitMac();                        /* Start the managers            */
  77.     
  78.     WorkRetCode = ColorCheck();                        /* Set "useColor" global        */
  79.  
  80.     UseResFile (initResRefNum);            
  81.     prRecHdl = (THPrint) (NewHandle (sizeof (TPrint)));    /* get handle for print rec    */
  82.     PrintDefault (prRecHdl);                            /* initialize print rec        */
  83.     prPortPtr = (TPPrPort) (NewPtr (sizeof (TPrPort)));    /* get ptr to prnt port        */
  84.  
  85.     WorkRetCode = SetUpMenus();                        /* set up the menus                */
  86.  
  87. /**    WorkRetCode = ShowInfoDlog(128);                /* display the "About" dialog    */
  88.  
  89.     myDragRect = screenBits.bounds;                    /* Set the boundries...            */
  90.     InsetRect(&myDragRect,10,10);                    /* ...for dragging                */
  91.     
  92.     for (j=0; j<windMax; j++)                        /* Indicate all entries in        */
  93.         windTbl[j].windPtr = 0;                        /*   windTbl are not in use        */
  94.     SetPt (&nextTextPosit, 10,40);                    /* Set posit of first text wind    */
  95.     
  96.     workRegionH = NewRgn();                            /* get region for TE clikloop    */
  97.  
  98.     WorkRetCode = MainGetProc();                    /* put the main window up        */
  99.  
  100.     myQuitFlag = 0;                                    /* set flag for main event loop    */
  101.     
  102.     WorkRetCode = FinderFilesProc();            /* process any files from finder    */
  103.  
  104.     /**************************                                                     */
  105.     /*    Main Event Loop          *                                                        */
  106.     /**************************                                                     */
  107.     while (myQuitFlag == 0)                        /* loop till quit                    */
  108.         {
  109.  
  110.         GetMouse (&locMouse);                    /* where is the mouse?                */
  111.         gMouse = locMouse;                        /* convert to ..                    */
  112.         LocalToGlobal(&gMouse);                    /* .. global coordinates            */
  113.         mouseWindPart = FindWindow (gMouse, &mouseWindPtr);        /* get ptr & part    */
  114.         CursorSelect (mouseWindPtr, mouseWindPart, NIL);    /* set cursor to match    */
  115.         
  116.         SystemTask();                            /* let system have some time        */
  117.         
  118.         if (GetNextEvent(everyEvent, &myEvent) != nullEvent)    /* if not nullEvent    */
  119.             {
  120.             switch (myEvent.what)
  121.                 {
  122.                 case (activateEvt):                /* activate or deactivate            */
  123.                     WorkRetCode = 
  124.                             WhichWindow((WindowPtr) myEvent.message, &windSub);
  125.                     if (WorkRetCode == 0)
  126.                         switch (windTbl[windSub].windRec.refCon)
  127.                             {
  128.                             case (ProcMain):
  129.                                 WorkRetCode = MainWindowProc();
  130.                             break;
  131.                             case (ProcText):
  132.                                 WorkRetCode = TextWindowProc();
  133.                             break;
  134.                             case (ProcHelp):
  135.                                 WorkRetCode = HelpWindowProc();
  136.                             break;
  137.                             }
  138.                 break;
  139.  
  140.                 case (mouseDown):
  141.                     WorkRetCode = MouseDownProc();
  142.                 break;
  143.                 
  144.                 case (mouseUp):
  145.                 break;
  146.                 
  147.                 case (diskEvt):
  148.                     if (HiWord(myEvent.message) != noErr)    /* if MountVol had err    */
  149.                         {                                    /* then initialize disk    */
  150.                         SysBeep(NIL);                                /* beep            */
  151.                         SetPt (&workPoint,30,40);                    /* position        */
  152.                         DIBadMount (workPoint, myEvent.message);    /* initialize    */
  153.                         }
  154.                 break;
  155.                 
  156.                 case (networkEvt):
  157.                 break;
  158.                 
  159.                 case (driverEvt):
  160.                 break;
  161.                 
  162.                 case (app1Evt):
  163.                 break;
  164.                 
  165.                 case (app2Evt):
  166.                 break;
  167.                 
  168.                 case (app3Evt):
  169.                 break;
  170.                 
  171.                 case (app4Evt):
  172.                 break;
  173.                 
  174.                 case (keyUp):
  175.                 break;
  176.                 
  177.                 case (keyDown):
  178.                 case (autoKey):
  179.                     WorkRetCode = KeyDownProc();
  180.                 break;
  181.                 
  182.                 case (updateEvt):
  183.                     WorkRetCode = 
  184.                             WhichWindow((WindowPtr) myEvent.message, &windSub);
  185.                     if (WorkRetCode == 0)
  186.                         {
  187.                         BeginUpdate(windTbl[windSub].windPtr);
  188.  
  189.                         switch (windTbl[windSub].windRec.refCon)
  190.                             {
  191.                             case (ProcMain):
  192.                                 WorkRetCode = MainDrawProc();
  193.                             break;
  194.                             case (ProcText):
  195.                                 WorkRetCode = TextDrawProc();
  196.                             break;
  197.                             case (ProcHelp):
  198.                                 WorkRetCode = HelpDrawProc();
  199.                             break;
  200.                             }
  201.                             
  202.                         EndUpdate(windTbl[windSub].windPtr);
  203.                         }
  204.                 break;
  205.                 }
  206.             }
  207.         else
  208.             {
  209.                                         /************************************/
  210.                                         /* null event                        */
  211.                                         /* The system doesn't need our        */
  212.                                         /* attention, so give one loop to    */
  213.                                         /* the proc associated with the        */
  214.                                         /* front window.                    */
  215.                                         /************************************/
  216.             workWindowPtr = FrontWindow();    /* which is front (active) ?    */
  217.             WorkRetCode = 
  218.                     WhichWindow(workWindowPtr, &k);    /* match ptr to table    */
  219.             if (WorkRetCode == 0)                    /* if it's a good match    */
  220.                 {                                    /* then                    */
  221.                 windSub = k;                        /*   set the subscrpt    */
  222.                 switch (windTbl[windSub].windRec.refCon)    /* window type    */
  223.                     {
  224.                     case (ProcMain):
  225.                         WorkRetCode = MainWindowProc();
  226.                     break;
  227.                     case (ProcText):
  228.                         WorkRetCode = TextWindowProc();
  229.                     break;
  230.                     case (ProcHelp):
  231.                         WorkRetCode = HelpWindowProc();
  232.                     break;
  233.                     }
  234.                 }
  235.             }
  236.         }
  237.     /**************************                                                     */
  238.     /* End of Main Event Loop *                                                        */
  239.     /**************************                                                     */
  240.  
  241.     WorkRetCode = MainCloseProc();                    /* close main window            */
  242.         
  243.     WorkRetCode = ShutMac();                        /* Shutdown routines            */
  244.  
  245.     return MainRetCode;                                /*        ALL DONE !!!            */
  246. }
  247. /************************************************************************************/
  248. /*    InitMac                                                                            */
  249. /*  This function initializes the managers which will be used by this program.        */
  250. /************************************************************************************/
  251. short InitMac(void)
  252. {
  253.     short        InitRetCode = 0;                    /* set the return code to good        */
  254.     
  255.                                                                                        
  256.     MaxApplZone();                                /* expand heap to max size            */
  257.     for (j=0; j<20; j++)                        /* get a bunch o' master pointers    */
  258.         MoreMasters();
  259.  
  260.     /************************************                                            */    
  261.     /* NOTE - don't change the order    *                                            */
  262.     /*  of these initialization routines*                                            */
  263.     /************************************                                            */                                                                                           
  264.     InitGraf(&thePort);                         /* intiialize QuickDraw             */
  265.     InitFonts();                                /* initialize Font Manager            */
  266.     InitWindows();                                /* initialize Window Manager        */
  267.     FlushEvents(everyEvent,0);                    /* initialize Event Manager            */
  268.     InitMenus();                                /* initialize Menu Manager            */
  269.     TEInit();                                    /* initialize TextEdit                */
  270.     InitDialogs(NIL);                            /* initialize Dialog Manager        */
  271.     PrOpen();                                    /* initialize Print Manager            */
  272.     InitCursor();                                /* initialize Cursor to arrow        */
  273.     
  274.     DILoad();                                    /* load the Disk Init package        */
  275.     
  276.                                                 /* Get resource file number    after    */
  277.     initResRefNum = CurResFile();                /* these loads and initializations    */
  278.     
  279.     return InitRetCode;
  280. }
  281.  
  282. /************************************************************************************/
  283. /*    ShutMac                                                                            */
  284. /*  This function does routines prior to program shutdown.                            */
  285. /************************************************************************************/
  286.  
  287. short ShutMac(void)
  288. {
  289.     short        SMRetCode = 0;                        /* set the return code to good        */
  290.     
  291.     PrClose();                                    /* close memory of Print Mgr        */
  292.     DIUnload();                                    /* delete disk init package            */    
  293.     DisposeRgn(workRegionH);                    /* release region for TE redraw        */
  294.  
  295.     return SMRetCode;
  296. }
  297.